package com.easybuy.entity;
import java.time.LocalDateTime;

/**
 * EasybuyUserAddress 实体类
 * 对应数据库表 easybuy.easybuy_user_address
 */
public class EasybuyUserAddress {
    // 主键id
    private Integer id;

    // 用户主键
    private Integer userId;

    // 地址
    private String address;

    // 创建时间
    private LocalDateTime createTime;

    // 是否是默认地址（1:是 0否）
    private Integer isDefault;

    // 备注
    private String remark;

    // 无参构造函数
    public EasybuyUserAddress() {
    }

    // 带参构造函数
    public EasybuyUserAddress(Integer id, Integer userId, String address,
                             LocalDateTime createTime, Integer isDefault, String remark) {
        this.id = id;
        this.userId = userId;
        this.address = address;
        this.createTime = createTime;
        this.isDefault = isDefault;
        this.remark = remark;
    }

    // Getter 和 Setter 方法
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public Integer getIsDefault() {
        return isDefault;
    }

    public void setIsDefault(Integer isDefault) {
        this.isDefault = isDefault;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    // 便捷方法：判断是否为默认地址
    public boolean isDefaultAddress() {
        return isDefault != null && isDefault == 1;
    }

    // 便捷方法：设置是否为默认地址
    public void setDefaultAddress(boolean isDefault) {
        this.isDefault = isDefault ? 1 : 0;
    }

    // 便捷方法：获取格式化后的创建时间
    public String getFormattedCreateTime() {
        if (createTime != null) {
            return createTime.toString().replace("T", " ");
        }
        return "";
    }

    // 便捷方法：获取地址简写（截取前20个字符）
    public String getShortAddress() {
        if (address != null && address.length() > 20) {
            return address.substring(0, 20) + "...";
        }
        return address;
    }

    // 便捷方法：验证地址是否有效
    public boolean isValidAddress() {
        return address != null && !address.trim().isEmpty() && address.length() >= 5;
    }

    @Override
    public String toString() {
        return "EasybuyUserAddress{" +
                "id=" + id +
                ", userId=" + userId +
                ", address='" + address + '\'' +
                ", createTime=" + createTime +
                ", isDefault=" + isDefault +
                ", remark='" + remark + '\'' +
                '}';
    }
}